/**************************************************************************
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
**************************************************************************/

package org.omegat.imports.adempiere;

import java.io.File;
import java.io.IOException;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;

/**
 *
 * @author  jker
 */
public class TrlFileScanner {

    private String filename;
    private TrlTMXSaver saver;
    
    public TrlFileScanner(String filename, TrlTMXSaver saver){
        this.filename = filename;
        this.saver = saver;
    }
    
    public void scan() throws IOException {
        System.out.println("Scaning File: " + filename);
        SAXBuilder builder = new SAXBuilder();
        try {
            Document doc = builder.build(new File(filename));
            Element root = doc.getRootElement();
            List<Element> childs = root.getChildren();
            for (Element c : childs) {
                List<Element> values = c.getChildren();

                for (Element v : values) {
                    String ov = v.getAttributeValue("original");
                    String rv = v.getValue();
                    if (ov.length() == 0) {

                    } else {
                        saver.add(ov, rv);
                    }
                }
            }
        } catch (JDOMException ex) {
            ex.printStackTrace();
        }
        
    }
    
}
